//
//  Calculator.m
//  CodeFor链式编程
//
//  Created by relax on 2017/11/16.
//  Copyright © 2017年 relax. All rights reserved.
//

#import "Calculator.h"



@implementation Calculator {
    // 最后计算的总数
    NSInteger _totalValue;
    // 个人介绍信息
    NSMutableString *_intro;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _totalValue = 0;
        _intro = [NSMutableString string];
    }
    return self;
}


- (Calculator *(^)(NSInteger sumNum))sum {
    return ^ Calculator * (NSInteger sumNum) {
        self->_totalValue += sumNum;
        return self;
    };
}

- (Calculator *(^)(NSInteger subNum))sub {
    return ^ Calculator * (NSInteger subNum) {
        self->_totalValue -= subNum;
        return self;
    };
}

- (Calculator *(^)(NSInteger))mutil {
    return ^ Calculator * (NSInteger mutilNum) {
        _totalValue = _totalValue * mutilNum;
        return self;
    };
}

- (Calculator *(^)(NSInteger))div {
    return ^ Calculator * (NSInteger divNum) {
        _totalValue /= divNum;
        return self;
    };
}

- (NSInteger)result {
    return _totalValue;
}

- (Calculator * (^)(NSString *name))name {
    return ^ Calculator * (NSString *name) {
        [_intro appendFormat:@"name : %@",name];

        return self;
    };
}


- (Calculator * (^)(NSString *address))address {
    return ^ Calculator * (NSString *address) {
        [_intro appendFormat:@"address : %@",address];

        return self;
    };
}


- (NSString *)introduction {
    return _intro.copy;
}

@end
